<template>
	<view class="content">
		<!-- 轮播图 -->
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular indicator-dots="true" :autoplay="false">
				<swiper-item v-if="detailInfo.videoKey">
					<video 
					class="item-video" 
					:controls="false" 
					loop="true"
					autoplay="true"
					:src="detailInfo.videoKey"
					object-fit="cover">
					</video>
				</swiper-item>
				<swiper-item v-for="(item, index) in myImgList" @click="clickBanner(item)" :key="item.id">
					<image :src="item.objKey"></image>
				</swiper-item>
			</swiper>
		</view>

		<!-- 位置信息 -->
		<view class="info-view">
			<view class="info-title">{{ detailInfo.locationName }}</view>
			<view class="info-content">
				<view class="info-list">
					<view class="info-item">{{ detailInfo.ticketPrice }}</view>
					<view class="info-item">{{ detailInfo.openinghours }}</view>
					<view class="info-item">{{ detailInfo.address }}</view>
				</view>
				<view class="btn-box">
					<view class="btn" @click="callPhoneNum">
						<uni-icons type="phone-filled" color="#00A2E9" size="16"></uni-icons>
						电话咨询
					</view>
					<view class="btn" @click="navigate">
						<uni-icons type="paperplane-filled" color="#00A2E9" size="16"></uni-icons>
						地图导航
					</view>
				</view>
			</view>
			<view class="flex justify-around margin-top">
				<view class="flex flex-1" @click="clickAudio">
					<uni-icons type="mic-filled" color="#00A2E9" size="20"></uni-icons>
					语音讲解
				</view>
				<view class="flex flex-1" @click="clickVR">
					<uni-icons type="camera-filled" color="#00A2E9" size="20"></uni-icons>
					VR全景
				</view>
			</view>
		</view>
		<!-- 详情介绍 -->
		<view class="descriotion-view">
			<rich-text :nodes="detailInfo.introduction" class="fload" :class="isFload ? 'hide' : 'show'"></rich-text>
			<view class="more-btn" @click="onFlag">{{ buttonText }}</view>
		</view>
		<!-- 周边推荐 -->
		<view class="recommend-view">
			<view class="recommend-title">周边推荐</view>
			<!-- 分类菜单 -->
			<!-- <view class="menu-view">
				<tabs :list="tabList" @tabItemClick="itemClick" marright="25px" activeWeight="600"></tabs>
			</view> -->
			<!-- <view class="recommend-list" v-for="(item, index) in recommendList" :key="item.id" @click="clickRecommend(item)">
				<image class="item-img" :src="item.img"></image>
				<view class="item-title">{{ item.name }}</view>
			</view> -->

			<view class="list-content">
				<view class="item-list" v-for="(item, index) in recommendList" :key="item.id" @click="clickRecommend(item)">
					<image mode="widthFix" :src="item.img" class="item-image"></image>
					<view class="item-title">{{ item.name }}</view>
					<!-- <view class="item-desc">{{ item.desc }}</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { forEach } from 'lodash';
import { getLocationDetails } from '@/api/index.js';
export default {
	components: {},
	data() {
		return {
			id: '',
			myImgList: [],
			//默认传到顶部菜单栏的数据
			tabList: [{ name: '住宿' }, { name: '美食' }],
			// 用于控制展开收起
			isFload: false,
			buttonText: '',
			recommendList: [],
			detailInfo: {},
			innerAudioContext: null
		};
	},
	mounted() {},
	onLoad(data) {
		this.id = data.id;
		console.log('id:', this.id);
		this.getDetails(this.id);
		this.onFlag();
	},
	onUnload() {
		if (this.innerAudioContext) {
			this.destroyAudio();
		}
	},
	methods: {
		getDetails(id) {
			let that = this;
			this.myImgList = [];
			uni.showLoading({});
			getLocationDetails(id).then((res) => {
				uni.hideLoading();
				console.log('res', res);
				if (res.data && res.code === 200) {
					that.detailInfo = res.data;
					that.recommendList = res.data.recommends;
					that.myImgList = res.data.pics;
				}
			});
		},
		onFlag() {
			if (this.isFload) {
				this.buttonText = '收起';
			} else {
				this.buttonText = '展开';
			}
			this.isFload = !this.isFload;
		},
		itemClick(item, index) {
			console.log(item, index);
		},
		clickBanner(item) {},
		clickRecommend(item) {
			const id = item.id;
			uni.navigateTo({
				url: `/pages/map/mapDetail?id=` + id
			});
		},
		clickAudio() {
			if (this.innerAudioContext) {
				this.destroyAudio();
			}
			this.playAudio();
		},
		destroyAudio() {
			this.innerAudioContext.pause();
			this.innerAudioContext.destroy();
			this.innerAudioContext = null
		},
		playAudio() {
			this.innerAudioContext = uni.createInnerAudioContext();
			this.innerAudioContext.autoplay = true;
			this.innerAudioContext.src = this.detailInfo.voiceKey;
			this.innerAudioContext.onPlay(() => {
				console.log('开始播放');
			});
			this.innerAudioContext.onError((res) => {
				console.log(res.errMsg);
				console.log(res.errCode);
			});
		},
		clickVR() {
			uni.navigateTo({
				url: `/pages/common/webview/index?title=${this.detailInfo.locationName}&url=${this.detailInfo.vrView}`
			});
		},
		navigate() {
			uni.openLocation({
				latitude: this.detailInfo.latitude,
				longitude: this.detailInfo.longitude,
				name: this.detailInfo.locationName,
				address: this.detailInfo.address,
				success: function () {
					console.log('success');
				}
			});
		},
		callPhoneNum() {
			uni.makePhoneCall({
				phoneNumber: this.detailInfo.phone
			});
		}
	}
};
</script>

<style lang="scss">
page {
	height: 100%;
	position: relative;
}
.content {
	width: 100%;
	height: 100%;
	background-color: #eeeeef;
}
.banner-view {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background-color: white;
}
.info-view {
	background: #fff;
	padding: 20rpx 40rpx;
	.info-content {
		display: flex;
		justify-content: space-between;
	}
	.info-item {
		font-size: 24rpx;
		line-height: 40rpx;
	}
	.btn-box {
		flex-shrink: 0;
		font-size: 24rpx;
		color: #00a2e9;
		.btn {
			line-height: 50rpx;
		}
	}
}
.info-title {
	font-size: 48rpx;
	margin-bottom: 20rpx;
	// padding-top: 20rpx;
	// margin-left: 45rpx;
	color: #ff0000;
}
// .info-price {
// 	font-size: 20rpx;
// 	/* margin-top: 15px; */
// 	padding-top: 20rpx;
// 	margin-left: 45rpx;
// }
// .info-openTime {
// 	font-size: 20rpx;
// 	/* margin-top: 15px; */
// 	padding-top: 20rpx;
// 	margin-left: 45rpx;
// }
// .info-address {
// 	font-size: 20rpx;
// 	/* margin-top: 15px; */
// 	padding-top: 20rpx;
// 	margin-left: 45rpx;
// }

.descriotion-view {
	// 展开
	background-color: white;
	margin-top: 20rpx;
	padding: 20rpx 40rpx;
}

.fload {
	width: 100%;
	height: auto;
	display: -webkit-box;
	word-break: break-all;
	-webkit-box-orient: vertical;
	/* 要显示多少行就改变line-clamp的数据,此处折叠起来显示一行*/
	-webkit-line-clamp: 3;
	overflow: hidden;
	text-overflow: ellipsis;
	/* padding: 10px; */
	background-color: white;
}
.hide {
	display: -webkit-box;
}
.show {
	display: block;
}
.more-btn {
	display: block;
	height: 30px;
	color: #417275;
	text-align: center;
	line-height: 30px;
	width: 100%;
}
.recommend-view {
	background-color: white;
	margin: 10px 0;
}

.recommend-title {
	margin-left: 40rpx;
	padding-top: 30rpx;
	font-size: 36rpx;
	color: #f0880d;
}
.list-content {
	padding: 30rpx;
	box-sizing: border-box;
	column-count: 2;
}
.item-list {
	break-inside: avoid;
	width: 330rpx;
	background-color: #ffffff;
	border-radius: 10rpx;
}
.swiper {
	height: 420rpx;
	image {
		width: 100%;
	}
}
.item-video {
	width: 100%;
	height: 420rpx;
}
.item-image {
	width: 100%;
	border-radius: 10rpx;
}
.item-title {
	padding: 20rpx;
	font-size: 30rpx;
	font-weight: bold;
}
/* .item-desc {
	margin: 15rpx;
	margin-top: 20rpx;
	display: flex;
	font-size: 26rpx;
	align-items: center;
	justify-content: space-between;
} */

/* .recommend-list {
	background-color: white;
	margin: 20px 20px 0 20px;
	border-radius: 10px;
	border-width: 1px;
	border-color: gray;
}
.item-img {
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
	width: 100%;
}
.item-title {
	padding: 20px;
	font-size: 20px;
	border-bottom-left-radius: 10px;
	border-bottom-right-radius: 1px;
	border-width: 1px;
	border-color: gray;
} */
</style>
